//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1999  Microsoft Corporation

Module Name:

parse.h

Abstract:


Notes:


--*/
/*
------------------------------------------------------------------------------
    Revision History
    Date                Author            Activity ID            Activity Headline
    2006-03-16          Wangxiaogang      CEDB00010042           W3K RIL Porting                
------------------------------------------------------------------------------
*/
#pragma once


//
struct LISTVALUEMAP {
    UINT nValue;
    DWORD dwFlag;
};

//
//
struct LISTSTRINGMAP {
    LPCSTR szString;
    DWORD dwFlag;
};


inline void SkipChars(const LPCSTR szData, LPCSTR& rszPointer, LPCSTR szChars)
{
    rszPointer = szData + strspn(szData,szChars);
}


BOOL MatchStringBeginning(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL MatchStringEnd(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL MatchStringAnywhere(const LPCSTR szString, const LPCSTR szMatch, LPCSTR& rszPointer);
BOOL MatchBytesEnd(const BYTE* const pbBytes, const UINT cbBytes, const BYTE* const pbMatch, const UINT cbMatch,
                   const BYTE*& rpbPointer);
BOOL MatchBytesAnywhere(const BYTE* const pbBytes, const UINT cbBytes, const BYTE* const pbMatch, const UINT cbMatch,
                   const BYTE*& rpbPointer);
BOOL MatchStringBeginningAndAcorrdingParamentNumber(const LPSTR szString, const LPSTR szMatch,DWORD paramentNumber, 
	            LPSTR& rszPointer);
BOOL ParseDWord(const LPCSTR szData, const BOOL fLeadingZerosAllowed, DWORD& rdw, LPCSTR& rszPointer);
BOOL ParseHexDWord(const LPCSTR szData, const BOOL fLeadingZerosAllowed, DWORD& rdw, LPCSTR& rszPointer);
BOOL ParseUInt(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseIntAsUInt(const LPCSTR szData, UINT& rnInit, LPCSTR& rszPointer);
BOOL ParseUIntAndVerifyAbove(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT nUpperBound, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseUIntAndVerifyBelow(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT nLowerBound, UINT& rnInt, LPCSTR& rszPointer);
BOOL ParseHexUInt(const LPCSTR szData, const BOOL fLeadingZerosAllowed, UINT& rnInt, LPCSTR& rszPointer);
// BOOL ParseDouble(const LPCSTR szData, double& rdbDouble, LPCSTR& rszPointer);
BOOL ParseFixedPoint(const LPCSTR szData, DWORD &rdwFixedPoint, LPCSTR& rszPointer);
BOOL ParseString(const LPCSTR szData, const LPSTR szOut, const UINT cbOut, LPCSTR& rszPointer);
BOOL ParseUnquotedString(const LPCSTR szData, const char chDelimiter, const LPSTR szOut, const UINT cbOut, LPCSTR& rszPointer);
BOOL ParseUnlimitedUnquotedString(const LPCSTR szData, const char chDelimiter, LPSTR& rszOut, UINT& rcbOut, LPCSTR& rszPointer);
BOOL ParseRange(const LPCSTR szData, RILRANGE& rrrRange, LPCSTR& rszPointer);
BOOL ParseRangesFromString(const LPCSTR szData, RILRANGE rgrrRange[], DWORD& rdwNumRanges, DWORD dwMaxRanges, LPCSTR& rszPointer);
BOOL ParseRangeList(const LPCSTR szData, const LISTVALUEMAP* const rglvmMapArray, const UINT nMapArrayLength, DWORD& rdwMask,
                    LPCSTR& rszPointer);
BOOL ParseStringList(const LPCSTR szData, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& rdwMask,
                     LPCSTR& rszPointer);
BOOL ParseRspPrefix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL ParseRspPostfix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL FindRspPostfix(const LPCSTR szData, LPCSTR& rszPointer);
BOOL ParseGetLocation(const LPCSTR szRsp, UINT& rnLocation, LPCSTR& rszPointer); // in msg.cpp

BOOL FlagFromValue(UINT nValue, const LISTVALUEMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& Flag);
BOOL FlagFromString(const LPCSTR szString, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, DWORD& Flag);

BOOL ValueFromFlag(UINT dwFlag, const LISTVALUEMAP* const rglsmMapArray, const UINT nMapArrayLength, UINT& Value);
BOOL StringFromFlag(UINT dwFlag, const LISTSTRINGMAP* const rglsmMapArray, const UINT nMapArrayLength, LPCSTR& szString);


BOOL ParseUnlimitedString(const LPCSTR szData, LPSTR& rszOut, UINT& rcbOut, LPCSTR& rszPointer);

BOOL EncodedStringSizeToUnicodeStringSize(ENCODING_TYPE enc, size_t cbIn, size_t &cbOut);
BOOL AppendEncodedString(ENCODING_TYPE enc, LPCWSTR pwszIn, LPSTR& pszOut, const LPSTR pszOutEnd, BOOL bAllowUnicode);
BOOL AppendQuotedEncodedString(ENCODING_TYPE enc, LPCWSTR pwszIn, LPSTR& pszOut, const PUCHAR pszOutEnd, BOOL bAllowUnicode);
BOOL ParseEncodedString(ENCODING_TYPE enc, LPCSTR pszIn, const LPCSTR pszInEnd, LPWSTR pwszOut, const LPWSTR pwszOutEnd);
BOOL ParseQuotedEncodedString(ENCODING_TYPE enc, LPCSTR& pszIn, LPWSTR pwszOut, const LPWSTR pwszOutEnd);

